using Microsoft.AspNetCore.Mvc;
using AppServiceDemo.Application.Orders;
using AppServiceDemo.Application.Orders.Dtos;

namespace AppServiceDemo.WebApi.Host.Controllers
{
    [ApiController]
    [Route("/Api/[controller]")]
    public class OrderController : ControllerBase
    {
        private readonly IOrderAppService _orderAppService;

        public OrderController(IOrderAppService orderAppService)
        {
            _orderAppService = orderAppService;
        }

        [HttpPost]
        public async Task<int> CreateOrder(CreateOrderDto createOrderDto)
        {
            return await _orderAppService.CreateAsync(createOrderDto);
        }

        [HttpPut("{id}")]
        public async Task<string> UpdateOrder(int id, UpdateOrderDto updateOrderDto)
        {
            return await _orderAppService.UpdateAsync(id, updateOrderDto);
        }

        [HttpDelete("{id}")]
        public async Task<int> DeleteOrder(int id)
        {
            return await _orderAppService.DeleteAsync(id);
        }

        [HttpPatch("{id}/Approval")]
        public async Task<int> ApproveOrder(int id)
        {
            return await _orderAppService.ApproveAsync(id);
        }

        [HttpPatch("{id}/Decline")]
        public async Task<int> DeclineOrder(int id)
        {
            return await _orderAppService.DeclineAsync(id);
        }

        [HttpPatch("{id}/Cancel")]
        public async Task<int> CancelOrder(int id)
        {
            return await _orderAppService.CancelAsync(id);
        }

        [HttpPatch("{id}/Name")]
        public async Task<string> UpdateName(int id, string name)
        {
            return await _orderAppService.PatchNameAsync(id, new PatchNameDto()
            {
                Name = name
            });
        }
    }
}